/* gm_serial.h -- Arquivo core do gearserial
 *
 * Copyright (C) 2008, Diogo F. S. Ramos <diogo.ramos@usp.br>
 * GEAR - Grupo de Estudos Avançados em Robótica
 * <http://www.sel.eesc.usp.br/gear>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef GM_SERIAL_H_
#define GM_SERIAL_H_

#include <termios.h>

#include "gm_utils.h"

/** Caminho padrão de serial */
#define GM_SERIAL_DEFAULT_PATH "/dev/ttyS0"

typedef struct gm_serial_t gm_serial_t;

/** Objeto para comunicar-se com o o robô através da serial. */
struct gm_serial_t
{
    char * path;
    int fd;
    struct termios options;
    int speed;

    int command_size;
    unsigned char * command;
    int command_repeat;

    unsigned char * conf;
    unsigned char * motor_1;
    unsigned char * motor_2;
    unsigned char * motor_3;

    unsigned int mascara1;
    unsigned int mascara2;

    struct timespec delay;
    struct timespec sobrando;

    gm_matrix_t * matrix_conv;
    gm_matrix_t * matrix_vels;
    gm_matrix_t * matrix_motor_vels;
};

gm_serial_t * gm_serial_new( const char *end, const char * serial_path );
void gm_serial_set_robot_forward( gm_serial_t * self, const unsigned char speed );
void gm_serial_set_robot_backward( gm_serial_t * self, const unsigned char speed );
void gm_serial_set_robot_turn_left( gm_serial_t * self, const unsigned char speed );
void gm_serial_set_robot_turn_right( gm_serial_t * self, const unsigned char speed );
void gm_serial_set_robot_stop( gm_serial_t * self );
void gm_serial_destroy( gm_serial_t * self );
void gm_serial_robot_kick( gm_serial_t * self, const int nivel );
void gm_serial_robot_dribble_enable( gm_serial_t * self, int enable );
void gm_serial_robot_set_vel_pwd( gm_serial_t * self, float vx, float vy, float va );
void gm_serial_robot_set_vel( gm_serial_t * self, float vx, float vy, float va );

#endif	/* GM_SERIAL_H_ */
